<%
   prop_out_name = property.out_name
   new_prefix = sprintf("%s%s%s", prefix, prefix.empty? ? "" : "_", prop_out_name)
   func_def = sprintf("set_unread_%s(inputv, curv):", new_prefix)
   can_do = has_readable_property(property)
-%>
<% if property.is_a?(Api::Type::Array) && property.item_type.is_a?(Api::Type::NestedObject) && can_do -%>


def <%= func_def %>
    if not (inputv and isinstance(inputv, list)):
        return

    if not (curv and isinstance(curv, list)):
        return
<%# no need to set nv if it is empty, because it can't change the real information -%>

    lcv = len(curv)
<%   identities = property.identities -%>
<%   if identities.nil? -%>
    for i in range(len(inputv)):
        if i >= lcv:
            break

        cv = curv[i]
        iv = inputv[i]
<%   else -%>
    q = []
    for iv in inputv:
        if len(q) == lcv:
            break

        cv = None
        for j in range(lcv):
            if j in q:
                continue

            cv = curv[j]
<%     identities.each do |k| -%>

<%       p = find_property(property, [k]) -%>
<%       if p.required -%>
            if iv["<%= k %>"] != cv["<%= k %>"]:
                continue
<%       else -%>
            if iv["<%= k %>"] and (iv["<%= k %>"] != cv["<%= k %>"]):
                continue
<%       end -%>
<%     end -%>

            q.append(j)
            break
        else:
            continue
<%   end -%>
<%   property.child_properties.each do |prop|
       c = set_unreadable_option(prop, new_prefix, "iv", "cv", 8)
-%>
<%     unless c.empty? -%>

<%= c %>
<%     end -%>
<%   end -%>
<%   property.child_properties.each do |prop| -%>
<%     next unless has_unreadable_property(prop) -%>
<%= lines(build_set_unread_option_method(new_prefix, prop)) -%>
<%   end -%>
<% elsif property.is_a?(Api::Type::NestedObject) && can_do -%>


def <%= func_def %>
    if not (inputv and isinstance(inputv, dict)):
        return

    if not (curv and isinstance(curv, dict)):
        return
<%   property.child_properties.each do |prop|
       c = set_unreadable_option(prop, new_prefix, "inputv", "curv", 4)
-%>
<%     unless c.empty? -%>

<%= c %>
<%     end -%>
<%   end -%>
<%   property.child_properties.each do |prop| -%>
<%     next unless has_unreadable_property(prop) -%>
<%= lines(build_set_unread_option_method(new_prefix, prop)) -%>
<%   end -%>
<% end # if property.is_a?(Api::Type::Array) -%>
